package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MineExamSituation;
import com.ruoyi.system.service.IMineExamSituationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考试情况Controller
 * 
 * @author ruoyi
 * @date 2025-01-14
 */
@RestController
@RequestMapping("/system/situation")
public class MineExamSituationController extends BaseController
{
    @Autowired
    private IMineExamSituationService mineExamSituationService;

    /**
     * 查询考试情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:situation:list')")
    @GetMapping("/list")
    public TableDataInfo list(MineExamSituation mineExamSituation)
    {
        startPage();
        List<MineExamSituation> list = mineExamSituationService.selectMineExamSituationList(mineExamSituation);
        return getDataTable(list);
    }

    /**
     * 导出考试情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:situation:export')")
    @Log(title = "考试情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MineExamSituation mineExamSituation)
    {
        List<MineExamSituation> list = mineExamSituationService.selectMineExamSituationList(mineExamSituation);
        ExcelUtil<MineExamSituation> util = new ExcelUtil<MineExamSituation>(MineExamSituation.class);
        util.exportExcel(response, list, "考试情况数据");
    }

    /**
     * 获取考试情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:situation:query')")
    @GetMapping(value = "/{examSituationId}")
    public AjaxResult getInfo(@PathVariable("examSituationId") Long examSituationId)
    {
        return success(mineExamSituationService.selectMineExamSituationByExamSituationId(examSituationId));
    }

    /**
     * 根据用户ID查询考试情况
     */
    @PreAuthorize("@ss.hasPermi('system:situation:list')")
    @GetMapping("/listByUserId/{userId}")
    public TableDataInfo listByUserId(@PathVariable("userId") Long userId) {
        // 启动分页
        startPage();

        // 调用服务层方法，获取数据
        List<MineExamSituation> list = mineExamSituationService.selectMineExamSituationByUserId(userId);

        // 返回分页数据
        return getDataTable(list);
    }

    /**
     * 根据考试ID查询考试情况
     */
    @PreAuthorize("@ss.hasPermi('system:situation:list')")
    @GetMapping("/listByExamId/{examId}")
    public TableDataInfo listByExamId(@PathVariable("examId") Long examId) {
        // 启动分页
        startPage();

        // 调用服务层方法，获取数据
        List<MineExamSituation> list = mineExamSituationService.selectMineExamSituationByExamId(examId);

        // 返回分页数据
        return getDataTable(list);
    }


    /**
     * 新增考试情况
     */
    @PreAuthorize("@ss.hasPermi('system:situation:add')")
    @Log(title = "考试情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MineExamSituation mineExamSituation)
    {
        return toAjax(mineExamSituationService.insertMineExamSituation(mineExamSituation));
    }

    /**
     * 修改考试情况
     */
    @PreAuthorize("@ss.hasPermi('system:situation:edit')")
    @Log(title = "考试情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MineExamSituation mineExamSituation)
    {
        return toAjax(mineExamSituationService.updateMineExamSituation(mineExamSituation));
    }

    /**
     * 删除考试情况
     */
    @PreAuthorize("@ss.hasPermi('system:situation:remove')")
    @Log(title = "考试情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examSituationIds}")
    public AjaxResult remove(@PathVariable Long[] examSituationIds)
    {
        return toAjax(mineExamSituationService.deleteMineExamSituationByExamSituationIds(examSituationIds));
    }
}
